home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.object,comp.lang.c++,comp.lang.java
- Path: newsfeed.acns.nwu.edu!ftpbox!mothost!schbbs!news
- From: shang@corp.mot.com (David L. Shang)
- Subject: Re: Java: What's the Big Deal?
- Reply-To: shang@corp.mot.com
- Organization: MOTOROLA
- Date: Mon, 1 Apr 1996 15:54:16 GMT
- Message-ID: <1996Apr1.155416.12816@schbbs.mot.com>
- References: <4jk4ee$7ri@newsbf02.news.aol.com>
- Sender: news@schbbs.mot.com (SCHBBS News Account)
- Nntp-Posting-Host: 129.188.128.126
-
- In article <4jk4ee$7ri@newsbf02.news.aol.com> youngbros@aol.com (YoungBros)
- writes:
- >
- > I am not sure if Java gc really work. Some of my applets exhaust memory
- > after running for a while. I remember reading that the 'finalize' method
- > is not guaranteed to be called. If so, then we can't avoid memory leak.
- > Am I wrong?
-
- The more a program depends on GC, the more likely it will exhaust memory;
- because the storage is collected only when all its references are
- no longer valid, not at the time when all its references are no longer
- used. Be careful, never make a variable's lifetime unecessarily longer
- than the required.
-
- The more a language depends on GC, the more likely its application will
- exhaust memory, or at the best, will make the operating system busy
- to crunch the memory. GC is not always required. For example:
-
- class point
- {
- public:
- float x;
- float y;
- float z;
- };
- class FaceSet
- {
- coordIndex point[];
- ...
- public:
- loadCoordIndex (char* file_name)
- {
- one million of points read here, and
- coordIndex is created as an array of
- a million of points.
- };
- };
-
- With Java's array, memory will be smashed into millions of small
- pieces. Here is a brief comparison:
-
- Java array C++ array
-
- pieces: 1,000,000 pieces 1 piece
-
- expence: 1,000,000 type refs + 3,000,000 floats
- 1,000,000 obj refs +
- 1,000,000 gc overheads +
- 3,000,000 floats
-
- allocation: 1,000,001 times 1 time
-
- free time: 1,000,001 times 1 time
-
-
- David Shang
-
-